package com.hspedu.furns.dao.impl;

import com.hspedu.furns.dao.BasicDAO;
import com.hspedu.furns.dao.OrderItemDAO;
import com.hspedu.furns.entity.OrderItem;

import java.util.List;

/**
 * @author 徐
 * @version 1.0
 */
public class OrderItemDAOImpl extends BasicDAO<OrderItem> implements OrderItemDAO {
    /**
     * 保存订单项到数据库
     * @param orderItem
     * @return
     */
    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "INSERT INTO `order_item`(`id`,`name`,`price`,`count`,`total_price`,`order_id`)\n" +
                "VALUES(?,?,?,?,?,?)";
        return update(sql,orderItem.getId(),orderItem.getName(),orderItem.getPrice(),
                orderItem.getCount(),orderItem.getTotalPrice(),orderItem.getOrderId());
    }

    /**
     * 根据订单id查询多条此订单购物记录
     * @param id
     * @return
     */
    @Override
    public List<OrderItem> showOrderItem(String id) {
        String sql = "SELECT `id`,`name`,`price`,`count`,`total_price` totalPrice,`order_id` orderId \n" +
                "FROM `order_item`\n" +
                "WHERE `order_id` = ?";
        return queryMulti(sql,OrderItem.class,id);
    }
}
